package cn.sdormitory.wx.controller;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.wx.utils.HttpClientUtils;
import cn.sdormitory.wx.utils.WXUtil;
import cn.sdormitory.wx.utils.WeatherDataCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/wx")
public class WXController {

    @Autowired
    WXUtil wxUtil;

    //转换工具类
    @Autowired
    HttpClientUtils httpClientUtils;

    @Autowired
    WeatherDataCreator weatherDataCreator;


    /**
     * 获取用户openId,
     * @param code
     * @return
     */
    @ResponseBody
    @GetMapping("/wxCallback")
    public CommonResult wxCallback(String code){
        Map map = wxUtil.wxToken(code);

        return CommonResult.success(map);
    }

//    @ResponseBody
//    @GetMapping("/testSend")
//    public CommonResult testSend() {
//
//        Map<String, Object> weatherDataMap = weatherDataCreator.createWeatherDataMap("七月","岳阳","晴","27℃","35℃");
//
//        JSONObject jsonObject = wxUtil.sendInfo("oq4GA6BEmrzcCiEMOqqNsAYELapw", "NaCre4HAVCYNM3ntRWahxY2tkWItDMYU1C5oacmj3OY",  weatherDataMap);
//
//        System.out.println("七月");
//        System.out.println(jsonObject);
//        return CommonResult.success(jsonObject);
//    }


}
